home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6263 < prev    next >
Encoding:
Text File  |  1996-08-05  |  12.7 KB  |  442 lines

  1. Path: earth.execpc.com!not-for-mail
  2. From: sdg@earth.execpc.com (Software Development Group)
  3. Newsgroups: comp.lang.c
  4. Subject: Help! C code under Win 3.11
  5. Date: 23 Feb 1996 09:55:44 -0600
  6. Organization: Exec-PC
  7. Message-ID: <4gko20$oha@earth.alpha.net>
  8. NNTP-Posting-Host: earth-le1.execpc.com
  9.  
  10.  
  11. Could someone please tell me why this C code is not working under
  12. Windows 3.11.  It compiles, but does nothing.  
  13.  
  14. The following code is main.c and there's another .c that has
  15. a function that's called from here.
  16.  
  17. Most importantly, I'd like some kind of print-handler working.
  18. At least that way I can see what's going on.
  19.  
  20.  
  21. Thanks for your help.
  22. -----
  23.  
  24. static char mc_version[] = "MATLAB Compiler 1.0 infun";
  25. /*
  26.  *  MATLAB Compiler: 1.0
  27.  *  Date: Oct 20, 1995
  28.  *  Arguments: -e main 
  29.  *  *** suppressing complex case: no complex arguments ***
  30.  */
  31. #include <math.h>
  32. #include "matrix.h"
  33. #include "mcc.h"
  34. #include "matlab.h"
  35. #include <stdio.h>
  36. #include <windows.h>
  37.  
  38. /* static array S0_ (1 x 2) real, line 7 */
  39. static double S0r_[] =
  40. {
  41.     4, 1, 
  42. };
  43. ...clipped a number of static arrays....
  44.  
  45. static Matrix S29_ = { {0}, mxFULL, mxDOUBLE, mxSTRING, 0,
  46.         1, 4, S29__r_, 0, -1, 0, {0} };
  47.  
  48.  
  49. static int totalcnt  = 0;
  50. static int upperlim  = 0;
  51. static int firsttime = 1;
  52. char *OutputBuffer;
  53.  
  54. void WinPrint(char *text)
  55. {
  56.         int cnt;
  57.  
  58.         if (firsttime) {
  59.                 OutputBuffer = (char *)mxCalloc(1028, 1);
  60.                 upperlim += 1028;
  61.                 firsttime = 0;
  62.         }
  63.  
  64.         cnt = strlen(text);
  65.         if (totalcnt + cnt >= upperlim) {
  66.                 char *TmpOut;
  67.                 TmpOut = (char *)mxCalloc(upperlim + 1028, 1);
  68.                 memcpy(TmpOut, OutputBuffer, upperlim);
  69.                 upperlim += 1028;
  70.                 mxFree(OutputBuffer);
  71.                 OutputBuffer = TmpOut;
  72.         }
  73.         strncat(OutputBuffer, text, cnt);
  74. }
  75.  
  76.  
  77. void WinFlush(void)
  78. {
  79.         MessageBox(NULL, OutputBuffer, "output test", MB_OK);
  80.         mxFree(OutputBuffer);
  81. }
  82.  
  83.  
  84. /* int*/
  85. /* main(int argc, char **argv)*/
  86. /* {*/
  87.  
  88. WINAPI
  89. WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  90. {
  91.  #define MAXCMDTOKENS 128
  92.  int argc = 0;
  93.  LPSTR argv[MAXCMDTOKENS];
  94.  
  95.    int     n;    /* Integer parameter from command line. */
  96.  
  97.    int ci_, i_, j_;
  98.    unsigned flags_;
  99.    Matrix *Mplhs_[32], *Mprhs_[32];
  100.    int nlhs_=1, nrhs_=0;
  101.    {
  102. /***************** Compiler Assumptions ****************
  103.  *
  104.  *       CM0_            complex vector/matrix temporary
  105.  *       RM0_            real vector/matrix temporary
  106.  *       S0_             <constant>
  107.  *       S1_             <constant>
  108.  *       S2_             <constant>
  109.  *       beta            complex vector/matrix
  110.  *       disp            <function>
  111.  *       ekp             complex vector/matrix
  112.  *       fclose          <function>
  113.  *       fid             real vector/matrix
  114.  *       fid             integer scalar  => fid_1
  115.  *       fopen           <function>
  116.  *       fprintf         <function>
  117.  *       fscanf          <function>
  118.  *       hkp             complex vector/matrix
  119.  *       initprnt        <function>
  120.  *       main            <function being defined>
  121.  *       pk0             complex vector/matrix
  122.  *       pk1             complex vector/matrix
  123.  *       r               complex vector/matrix
  124.  *       rlse            <function>
  125.  *       thetakp0        complex vector/matrix
  126.  *       thetakp1        complex vector/matrix
  127.  *******************************************************/
  128.       Matrix fid;
  129.       Matrix thetakp0;
  130.       Matrix ekp;
  131.       Matrix hkp;
  132.       Matrix pk0;
  133.       Matrix r;
  134.       Matrix beta;
  135.       Matrix thetakp1;
  136.       Matrix pk1;
  137.       int fid_1;
  138.       Matrix RM0_;
  139.       Matrix CM0_;
  140.       
  141.       mccRealInit(fid);
  142.       mccComplexInit(thetakp0);
  143.       mccComplexInit(ekp);
  144.       mccComplexInit(hkp);
  145.       mccComplexInit(pk0);
  146.       mccComplexInit(r);
  147.       mccComplexInit(beta);
  148.       mccComplexInit(thetakp1);
  149.       mccComplexInit(pk1);
  150.       mccRealInit(RM0_);
  151.       mccComplexInit(CM0_);
  152.       
  153.       
  154.    mlfSetPrintHandler(WinPrint);
  155.       
  156.       /* fid = fopen('thetakp0.txt'); */
  157.       mccImport(&fid, (Matrix *) mlfFopen(0, 0, &S3_, 0, 0), 1, 5);
  158.       /* if fid == -1 disp('error opening thetakp0.txt'); end */
  159.       RM0_.dmode = mxNUMBER;
  160.       {
  161.          int m_=1, n_=1, cx_ = 0;
  162.          double t_;
  163.          double *p_RM0_;
  164.          int I_RM0_=1;
  165.          double *p_fid;
  166.          int I_fid=1;
  167.          m_ = mcmCalcResultSize(m_, &n_, fid.m, fid.n);
  168.          mccAllocateMatrix(&RM0_, m_, n_);
  169.          I_RM0_ = (RM0_.m != 1 || RM0_.n != 1);
  170.          p_RM0_ = RM0_.pr;
  171.          I_fid = (fid.m != 1 || fid.n != 1);
  172.          p_fid = fid.pr;
  173.          for (j_=0; j_<n_; ++j_)
  174.          {
  175.             for (i_=0; i_<m_; ++i_, p_RM0_+=I_RM0_, p_fid+=I_fid)
  176.             {
  177.                *p_RM0_ = (((int)*p_fid) == -1);
  178.                ;
  179.             }
  180.          }
  181.       }
  182.       RM0_.dmode = mxNUMBER;
  183.       if (mccIfCondition(&RM0_))
  184.       {
  185.          (void) mlfDisp(&S4_);
  186.    WinFlush();
  187.       }
  188.       /* thetakp0 = fscanf(fid,'%G',[4,1]); */
  189.       mccImport(&thetakp0, (Matrix *) mlfFscanf(0, &fid, &S5_, &S0_), 1, 7);
  190.       /* fclose(fid); */
  191.       Mplhs_[0] = (Matrix *) mlfFclose(&fid);
  192.       mccFreeMatrix(Mplhs_[0]);
  193.       
  194.       /* fid = fopen('ekp.txt'); */
  195.       mccImport(&fid, (Matrix *) mlfFopen(0, 0, &S6_, 0, 0), 1, 10);
  196.       /* if fid == -1 disp('error opening ekp.txt'); end */
  197.       RM0_.dmode = mxNUMBER;
  198.       {
  199.          int m_=1, n_=1, cx_ = 0;
  200.          double t_;
  201.          double *p_RM0_;
  202.          int I_RM0_=1;
  203.          double *p_fid;
  204.          int I_fid=1;
  205.          m_ = mcmCalcResultSize(m_, &n_, fid.m, fid.n);
  206.          mccAllocateMatrix(&RM0_, m_, n_);
  207.          I_RM0_ = (RM0_.m != 1 || RM0_.n != 1);
  208.          p_RM0_ = RM0_.pr;
  209.          I_fid = (fid.m != 1 || fid.n != 1);
  210.          p_fid = fid.pr;
  211.          for (j_=0; j_<n_; ++j_)
  212.          {
  213.             for (i_=0; i_<m_; ++i_, p_RM0_+=I_RM0_, p_fid+=I_fid)
  214.             {
  215.                *p_RM0_ = (((int)*p_fid) == -1);
  216.                ;
  217.             }
  218.          }
  219.       }
  220.       RM0_.dmode = mxNUMBER;
  221.       if (mccIfCondition(&RM0_))
  222.       {
  223.          (void) mlfDisp(&S7_);
  224.    WinFlush();
  225.       }
  226.       /* ekp = fscanf(fid,'%G'); */
  227.       mccImport(&ekp, (Matrix *) mlfFscanf(0, &fid, &S8_, 0), 1, 12);
  228.       /* fclose(fid); */
  229.       Mplhs_[0] = (Matrix *) mlfFclose(&fid);
  230.       mccFreeMatrix(Mplhs_[0]);
  231.       
  232.       /* fid = fopen('hkp.txt'); */
  233.       mccImport(&fid, (Matrix *) mlfFopen(0, 0, &S9_, 0, 0), 1, 15);
  234.       /* if fid == -1 disp('error opening hkp.txt'); end */
  235.       RM0_.dmode = mxNUMBER;
  236.       {
  237.          int m_=1, n_=1, cx_ = 0;
  238.          double t_;
  239.          double *p_RM0_;
  240.          int I_RM0_=1;
  241.          double *p_fid;
  242.          int I_fid=1;
  243.          m_ = mcmCalcResultSize(m_, &n_, fid.m, fid.n);
  244.          mccAllocateMatrix(&RM0_, m_, n_);
  245.          I_RM0_ = (RM0_.m != 1 || RM0_.n != 1);
  246.          p_RM0_ = RM0_.pr;
  247.          I_fid = (fid.m != 1 || fid.n != 1);
  248.          p_fid = fid.pr;
  249.          for (j_=0; j_<n_; ++j_)
  250.          {
  251.             for (i_=0; i_<m_; ++i_, p_RM0_+=I_RM0_, p_fid+=I_fid)
  252.             {
  253.                *p_RM0_ = (((int)*p_fid) == -1);
  254.                ;
  255.             }
  256.          }
  257.       }
  258.       RM0_.dmode = mxNUMBER;
  259.       if (mccIfCondition(&RM0_))
  260.       {
  261.          (void) mlfDisp(&S10_);
  262.    WinFlush();
  263.       }
  264.       /* hkp = fscanf(fid,'%G',[4,1]); */
  265.       mccImport(&hkp, (Matrix *) mlfFscanf(0, &fid, &S11_, &S1_), 1, 17);
  266.       /* fclose(fid); */
  267.       Mplhs_[0] = (Matrix *) mlfFclose(&fid);
  268.       mccFreeMatrix(Mplhs_[0]);
  269.       
  270.       /* fid = fopen('pk0.txt'); */
  271.       mccImport(&fid, (Matrix *) mlfFopen(0, 0, &S12_, 0, 0), 1, 20);
  272.       /* if fid == -1 disp('error opening pk0.txt'); end */
  273.       RM0_.dmode = mxNUMBER;
  274.       {
  275.          int m_=1, n_=1, cx_ = 0;
  276.          double t_;
  277.          double *p_RM0_;
  278.          int I_RM0_=1;
  279.          double *p_fid;
  280.          int I_fid=1;
  281.          m_ = mcmCalcResultSize(m_, &n_, fid.m, fid.n);
  282.          mccAllocateMatrix(&RM0_, m_, n_);
  283.          I_RM0_ = (RM0_.m != 1 || RM0_.n != 1);
  284.          p_RM0_ = RM0_.pr;
  285.          I_fid = (fid.m != 1 || fid.n != 1);
  286.          p_fid = fid.pr;
  287.          for (j_=0; j_<n_; ++j_)
  288.          {
  289.             for (i_=0; i_<m_; ++i_, p_RM0_+=I_RM0_, p_fid+=I_fid)
  290.             {
  291.                *p_RM0_ = (((int)*p_fid) == -1);
  292.                ;
  293.             }
  294.          }
  295.       }
  296.       RM0_.dmode = mxNUMBER;
  297.       if (mccIfCondition(&RM0_))
  298.       {
  299.          (void) mlfDisp(&S13_);
  300.    WinFlush();
  301.       }
  302.       /* pk0 = fscanf(fid,'%G',[4,4]); */
  303.       mccImport(&pk0, (Matrix *) mlfFscanf(0, &fid, &S14_, &S2_), 1, 22);
  304.       /* fclose(fid); */
  305.       Mplhs_[0] = (Matrix *) mlfFclose(&fid);
  306.       mccFreeMatrix(Mplhs_[0]);
  307.       
  308.       /* fid = fopen('r.txt'); */
  309.       mccImport(&fid, (Matrix *) mlfFopen(0, 0, &S15_, 0, 0), 1, 25);
  310.       /* if fid == -1 disp('error opening r.txt'); end */
  311.       RM0_.dmode = mxNUMBER;
  312.       {
  313.          int m_=1, n_=1, cx_ = 0;
  314.          double t_;
  315.          double *p_RM0_;
  316.          int I_RM0_=1;
  317.          double *p_fid;
  318.          int I_fid=1;
  319.          m_ = mcmCalcResultSize(m_, &n_, fid.m, fid.n);
  320.          mccAllocateMatrix(&RM0_, m_, n_);
  321.          I_RM0_ = (RM0_.m != 1 || RM0_.n != 1);
  322.          p_RM0_ = RM0_.pr;
  323.          I_fid = (fid.m != 1 || fid.n != 1);
  324.          p_fid = fid.pr;
  325.          for (j_=0; j_<n_; ++j_)
  326.          {
  327.             for (i_=0; i_<m_; ++i_, p_RM0_+=I_RM0_, p_fid+=I_fid)
  328.             {
  329.                *p_RM0_ = (((int)*p_fid) == -1);
  330.                ;
  331.             }
  332.          }
  333.       }
  334.       RM0_.dmode = mxNUMBER;
  335.       if (mccIfCondition(&RM0_))
  336.       {
  337.          (void) mlfDisp(&S16_);
  338.    WinFlush();
  339.       }
  340.       /* r = fscanf(fid,'%G'); */
  341.       mccImport(&r, (Matrix *) mlfFscanf(0, &fid, &S17_, 0), 1, 27);
  342.       /* fclose(fid); */
  343.       Mplhs_[0] = (Matrix *) mlfFclose(&fid);
  344.       mccFreeMatrix(Mplhs_[0]);
  345.       
  346.       /* fid = fopen('beta.txt'); */
  347.       mccImport(&fid, (Matrix *) mlfFopen(0, 0, &S18_, 0, 0), 1, 30);
  348.       /* if fid == -1 disp('error opening beta.txt'); end */
  349.       RM0_.dmode = mxNUMBER;
  350.       {
  351.          int m_=1, n_=1, cx_ = 0;
  352.          double t_;
  353.          double *p_RM0_;
  354.          int I_RM0_=1;
  355.          double *p_fid;
  356.          int I_fid=1;
  357.          m_ = mcmCalcResultSize(m_, &n_, fid.m, fid.n);
  358.          mccAllocateMatrix(&RM0_, m_, n_);
  359.          I_RM0_ = (RM0_.m != 1 || RM0_.n != 1);
  360.          p_RM0_ = RM0_.pr;
  361.          I_fid = (fid.m != 1 || fid.n != 1);
  362.          p_fid = fid.pr;
  363.          for (j_=0; j_<n_; ++j_)
  364.          {
  365.             for (i_=0; i_<m_; ++i_, p_RM0_+=I_RM0_, p_fid+=I_fid)
  366.             {
  367.                *p_RM0_ = (((int)*p_fid) == -1);
  368.                ;
  369.             }
  370.          }
  371.       }
  372.       RM0_.dmode = mxNUMBER;
  373.       if (mccIfCondition(&RM0_))
  374.       {
  375.          (void) mlfDisp(&S19_);
  376.    WinFlush();
  377.       }
  378.       /* beta = fscanf(fid,'%G'); */
  379.       mccImport(&beta, (Matrix *) mlfFscanf(0, &fid, &S20_, 0), 1, 32);
  380.       /* fclose(fid); */
  381.       Mplhs_[0] = (Matrix *) mlfFclose(&fid);
  382.       mccFreeMatrix(Mplhs_[0]);
  383.       
  384.       /* [thetakp1,pk1]=rlse(thetakp0,ekp,hkp',pk0,r,beta); */
  385.       mccConjTrans(&CM0_, &hkp);
  386.       mccImport(&thetakp1, (Matrix *) mlfRlse(&Mplhs_[1], &thetakp0, &ekp, &CM0_, &pk0, &r, &beta), 1, 35);
  387.       mccImport(&pk1, Mplhs_[ 1 ], 1, 35);
  388.       
  389.       /* fid = fopen('thetakp1.txt','w'); */
  390.       Mplhs_[0] = (Matrix *) mlfFopen(0, 0, &S21_, &S22_, 0);
  391.       fid_1 = mccImportReal(0, Mplhs_[ 0 ], " (main, line 37): fid_1");
  392.       /* if fid == -1 disp('error opening thetakp1.txt for write'); end */
  393.       if ((fid_1 == -1))
  394.       {
  395.          (void) mlfDisp(&S23_);
  396.    WinFlush();
  397.       }
  398.       /* fprintf(fid,'%G %G %G %G\n',thetakp1); */
  399.       Mplhs_[0] = (Matrix *) mlfFprintf(mccTempMatrix((double)(fid_1), 0., mxNUMBER), &S24_, &thetakp1, 0);
  400.       mccFreeMatrix(Mplhs_[0]);
  401.    WinFlush();
  402.       /* fclose(fid); */
  403.       Mplhs_[0] = (Matrix *) mlfFclose(mccTempMatrix((double)(fid_1), 0., mxNUMBER));
  404.       mccFreeMatrix(Mplhs_[0]);
  405.       
  406.       /* fid = fopen('pk1.txt','w'); */
  407.       Mplhs_[0] = (Matrix *) mlfFopen(0, 0, &S25_, &S26_, 0);
  408.       fid_1 = mccImportReal(0, Mplhs_[ 0 ], " (main, line 42): fid_1");
  409.       /* if fid == -1 disp('error opening pk1.txt'); end */
  410.       if ((fid_1 == -1))
  411.       {
  412.          (void) mlfDisp(&S27_);
  413.    WinFlush();
  414.       }
  415.       /* fprintf(fid,'%G %G %G %G\n',pk1); */
  416.       Mplhs_[0] = (Matrix *) mlfFprintf(mccTempMatrix((double)(fid_1), 0., mxNUMBER), &S28_, &pk1, 0);
  417.       mccFreeMatrix(Mplhs_[0]);
  418.    WinFlush();
  419.       /* fclose(fid); */
  420.       Mplhs_[0] = (Matrix *) mlfFclose(mccTempMatrix((double)(fid_1), 0., mxNUMBER));
  421.       mccFreeMatrix(Mplhs_[0]);
  422.       
  423.       /* disp('done'); */
  424.       (void) mlfDisp(&S29_);
  425.    WinFlush();
  426.       mccFreeMatrix(&fid);
  427.       mccFreeMatrix(&thetakp0);
  428.       mccFreeMatrix(&ekp);
  429.       mccFreeMatrix(&hkp);
  430.       mccFreeMatrix(&pk0);
  431.       mccFreeMatrix(&r);
  432.       mccFreeMatrix(&beta);
  433.       mccFreeMatrix(&thetakp1);
  434.       mccFreeMatrix(&pk1);
  435.       mccFreeMatrix(&RM0_);
  436.       mccFreeMatrix(&CM0_);
  437.       return(0);
  438.    WinFlush();
  439.    }
  440. }
  441.  
  442.